local skel = fk.CreateSkill {
  name = "lb__guiwu",
  tags = { Skill.Wake }
}

Fk:loadTranslationTable {
  ["lb__guiwu"] = "归无",
  --[":lb__guiwu"] = "<b>觉醒技</b>，当弃牌堆中有十二张武器牌时，你失去<a href=':lb__xunshu'><font color='red'>〖寻赎〗</font></a>，获得<a href=':lb__juju'><font color='red'>〖踽踽〗</font></a>与弃牌堆中所有武器牌，之后视为使用一张目标为所有其他角色的【杀】，受到此【杀】伤害的角色死亡。",
  --9.23
  --[":lb__guiwu"] = "<b>觉醒技</b>，当牌堆中没有武器牌时，你失去<a href=':lb__xunshu'><font color='red'>〖寻赎〗</font></a>，获得<a href=':lb__juju'><font color='red'>〖踽踽〗</font></a>与弃牌堆中所有武器牌，之后视为使用一张目标为所有其他角色的【杀】，受到此【杀】伤害的角色死亡。",
  --9.30
  [":lb__guiwu"] = "<b>觉醒技</b>，当牌堆中没有武器牌时，你失去<a href=':lb__xunshu'><font color='red'>〖寻赎〗</font></a>，获得<a href=':lb__juju'><font color='red'>〖踽踽〗</font></a>与弃牌堆中所有武器牌，之后视为使用一张目标为所有其他角色的【杀】，且你可令受到此【杀】伤害的角色死亡。",

  ["#lb__guiwu"] = "归无：你可令 %dest 死亡",
  ["@$lb__guiwu"] = "归无",

  ["$lb__guiwu1"] = "忘川无波澜，引渡徘徊。",
  ["$lb__guiwu2"] = "我为逝者哀哭。",
}

skel:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
        and not table.find(player.room.draw_pile, function(id)
          return Fk:getCardById(id).sub_type == Card.SubtypeWeapon
        end)
  end,
  can_wake = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-lb__xunshu|lb__juju", nil, true, false)
    local cards = table.filter(room.discard_pile, function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeWeapon
    end)
    if #cards > 0 and not player.dead then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
    end
    if player.dead then return false end
    local tos = Fk:cloneCard("slash"):getAvailableTargets(player, { bypass_distances = true, bypass_times = true })
    room:useVirtualCard("slash", nil, player, tos, skel.name, true, {lb__guiwu = player})
  end,
})
--[[  不用宝宝标记了
skel:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 then
      local num = 0
      for _, id in ipairs(player.room.discard_pile) do
        if Fk:getCardById(id).sub_type == Card.SubtypeWeapon then
          num = num + 1
        end
      end
      return num == 12
    end
  end,
  can_wake = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-lb__xunshu|lb__juju", nil, true, false)
    local cards = table.filter(room.discard_pile, function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeWeapon
    end)
    if #cards > 0 and not player.dead then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
    end
    if player.dead then return false end
    local tos = Fk:cloneCard("slash"):getAvailableTargets(player, { bypass_distances = true, bypass_times = true })
    room:useVirtualCard("slash", nil, player, tos, skel.name, true)
  end,
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(skel.name, true, true) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          return true
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    skel:onAcquire(player, false)
  end,
})

skel:addAcquireEffect(function(self, player, is_start)
  local room = player.room
  local ids = {}
  for _, id in ipairs(room.discard_pile) do
    if Fk:getCardById(id).sub_type == Card.SubtypeWeapon then
      table.insert(ids, id)
    end
  end
  room:setPlayerMark(player, "@$lb__guiwu", #ids == 0 and 0 or ids)
end)

skel:addLoseEffect(function(self, player, is_death)
  player.room:setPlayerMark(player, "@$lb__guiwu", 0)
end)

--]]

skel:addEffect(fk.Damaged, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local parent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true) --父事件
    if data.from and not target.dead and parent and parent.data
    and parent.data.extra_data and parent.data.extra_data.lb__guiwu
    and not data.prevented then
      local killer = parent.data.extra_data.lb__guiwu ---@type ServerPlayer
      if killer and killer:isAlive() then
        event:setCostData(self, {killer = killer})
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(event:getCostData(self).killer, {skill_name = skel.name, prompt = "#lb__guiwu::"..target.id})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local killer = event:getCostData(self).killer
    --room:notifySkillInvoked(killer, skel.name, "offensive", {target})
    room:killPlayer{
      who = target,
      killer = killer,
    }
  end,
})

return skel
